/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import DB_REDIS.Redis_Rd;
import DB_REDIS.Redis_W;
import java.util.HashMap;
import java.util.Map;
import libCore.Config;
import share.KeysDefinition;
import share.ShareMacros;

/**
 *
 * @author LinhTA
 */
public class ModelUser {
   
    String _uid ;
     
    public ModelUser(String uid)
    {
        _uid = uid;
    }
    
    public Map<String,String> getInfo(String fid, String mid)
    {
        Map<String,String> data = new HashMap<String,String>();
        
        data =  Redis_Rd.getInstance().hget(_uid);
        data.put(ShareMacros.FACEID, fid);
        data.put(ShareMacros.MEID,mid);
       

        if(!data.containsKey(ShareMacros.EXP))
           data.put(ShareMacros.EXP, "0");
  
       data.put(ShareMacros.COIN, ModelItem.getCountItem(_uid, ShareMacros.COIN));
       data.put(ShareMacros.GOLD, ModelItem.getCountItem(_uid, ShareMacros.GOLD));
       
       return data;
    }
            
    public Map<String, String> buyLife()
    {
        Map<String,String> data = new HashMap<String,String>();
        data.put(ShareMacros.SUSSCES, "false");
        
        Map<String,String> dataLife = ModelItem.getLifeVSTime(_uid, null);
        String lifeStr = dataLife.get(ShareMacros.LIFE);
        String lifeMaxStr = Config.getParam(ShareMacros.MAX, ShareMacros.LIFE);
        int life = Integer.parseInt(lifeStr);
        int lifeMax = Integer.parseInt(lifeMaxStr);
        if(lifeMax <= life)
            return data;
        
        
        String coinStr = ModelItem.getCountItem(_uid, ShareMacros.COIN);
        
        
        return  data;
    }
    
    
//    public int getCoin(String uid)
//     {
//         //String keyCoin = KeysDefinition.getKeyCoinUser(uid);
//         String coin="";
//          int retries = configuration.Configuration.retries;
//         while(retries>0)
//         {
//             coin = Redis_Rd.getInstance().Hget(uid, ShareMacros.COIN);
//             if(coin.isEmpty() || coin == null)
//                 retries --;
//             else break;
//         }
//               
//         if(coin.isEmpty() || coin == null)
//         {
//             retries = configuration.Configuration.retries;
//              while(retries>0)
//            {
//                long ret = Redis_W.getInstance().hincrBy(uid, ShareMacros.COIN,Long.parseLong(Config.getParam("defaultUser", ShareMacros.COIN)));
//                if(ret >= -1)
//                    retries --;
//                else
//                {
//                    String retString = String.valueOf(ret);
//                    coin = Integer.valueOf(retString);
//                    break;
//                }
//            }
//         }
//         
//         return coin;
//         
//     }
    
}
